//
//  RankingModel.m
//  CoolTennisBall
//
//  Created by Coollang on 2017/7/27.
//  Copyright © 2017年 CoolLang. All rights reserved.
//

#import "RankingModel.h"

@implementation RankingModel

- (instancetype)init {
    if (self = [super init]){
        // 设置默认值
        _score = @"0";
        _userID = @"";
        _userName = @"--";
        _headIcon = @"";
        _address = @"";
        _signature = @"";
        _totalCount = @"0";
        _duration = @"0";
        _maxSpeed = @"0";
        _likes = @"0";
    }
    return self;
}

+ (instancetype)rankIngModelWithDict:(NSDictionary *)dict {
    RankingModel *model = [[RankingModel alloc] initWithDictionary:dict];
    return model;
}

- (instancetype)initWithDictionary:(NSDictionary *)dic{
    
    if ([self init]) {
        _isLiked = [dic[@"IsLiked"] boolValue];
        _score = dic[@"Score"];
        _userID = dic[@"UserID"];
        _userName = dic[@"UserName"];
        _headIcon = dic[@"Icon"];
        _address = [self updateValueWithDict:dic key:@"Address"];
        _signature = dic[@"Signature"];
        _totalCount = dic[@"TotalCount"];
        _duration = dic[@"Duration"];
        _maxSpeed = dic[@"MaxSpeed"];
        _likes = dic[@"Likes"];
    }
    
    return self;
}

- (id)updateValueWithDict:(NSDictionary *)dict key:(NSString *)key {
    if ([dict.allKeys containsObject:key]){
        return dict[key];
    }else {
        return nil;
    }
}


- (NSString *)valueWithRankModeType:(RankModeType)type {
    switch (type) {
        case RankModeTypeMaxSpeed:
            return self.maxSpeed;
            break;
        case RankModeTypeAvgScore:
            return self.score;
            break;
        case RankModeTypeSwings:
            return self.totalCount;
            break;
    }
}

@end
